package controllers;

import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.util.List;

import javax.swing.JOptionPane;

import baseClasses.Clipart;
import baseClasses.GameType;
import baseGame.Game;
import drawableClasses.FindGame;
import drawableClasses.MainMenu;
import enums.GameScreenStatus;

public class GameControl {
	private GameScreenStatus currentScreen;
	private GameType currentGame;
	
	public GameControl(){
		callMenu();
	}
	
	public void callIntro(){

	}

	public void callMenu(){
		currentScreen = GameScreenStatus.MainMenu;
		currentGame = new MainMenu();
	}

	public void callFindGame(){
		currentScreen = GameScreenStatus.FindGame;
		currentGame = new FindGame();
	}

	public void clickedAction(MouseEvent e) {
		switch (currentScreen) {
		case MainMenu:
			if(currentGame instanceof MainMenu){
				((MainMenu) currentGame).clickedAction(e);
				currentScreen = ((MainMenu)currentGame).checkCanChangeScreen();
				
				if(currentScreen != GameScreenStatus.MainMenu){
					this.currentGame = null;
					nextScreen();
				}
				
			}else{
				//TODO: EXCEPTION
			}
			break;

		case ErrorsGame:
			break;

		case FindGame:
			if(currentGame instanceof FindGame){
				FindGame fd = ((FindGame) currentGame);
				fd.clickedAction(e);
				
				findGameHudDraw(fd.getCliparts());
				
				if(currentScreen != GameScreenStatus.FindGame){
					this.currentGame = null;
					nextScreen();
				}
				
			}else{
				//TODO: EXCEPTION
			}
			break;

		case Config:

			break;

		case QuizGame:

			break;

		case Ranking:

			break;
		}
	}

	private void findGameHudDraw(List<Clipart> cliparts) {
		for(Clipart c : cliparts){
			if(c.getCena() == Clipart.FINDED){
				//TODO: HUD
			}
		}
	}

	private void nextScreen() {
		switch (currentScreen) {
		case MainMenu:
			callMenu();
			break;

		case ErrorsGame:
			break;

		case FindGame:
			callFindGame();
			break;

		case Config:

			break;

		case QuizGame:

			break;

		case Ranking:

			break;
		}		
	}

	public GameScreenStatus getCurrentScreen() {
		return currentScreen;
	}

	public void setCurrentScreen(GameScreenStatus currentScreen) {
		this.currentScreen = currentScreen;
	}

	public void update() {
		switch (currentScreen) {
		case ErrorsGame:
			break;

		case FindGame:
			((FindGame)currentGame).update();
			break;

		case Config:

			break;

		case QuizGame:

			break;

		case Ranking:

			break;
		}		
	}

	public GameType getCurrentGame() {
		return currentGame;
	}

	public void setCurrentGame(GameType currentGame) {
		this.currentGame = currentGame;
	}
}
